package com.school.gift.service.impl;

import com.school.gift.domain.SysConfig;
import com.school.gift.mapper.SysConfigMapper;
import com.school.gift.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zhibi.common.support.base.service.BaseServiceImpl;
import zhibi.common.support.context.ContextConfig;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * Created by 执笔 on 2017/3/15.
 */
@Service
@Transactional
public class SysConfigServiceImpl extends BaseServiceImpl<SysConfig> implements SysConfigService{

    @Autowired
    public SysConfigServiceImpl(SysConfigMapper mapper) {
        super(mapper);
        sysConfigMapper = mapper;
    }
    private SysConfigMapper sysConfigMapper;


    @Override
    public void updateContextConfig() {
        List<SysConfig> sysConfigs = sysConfigMapper.selectAll();
        ServletContext servletContext = ContextConfig.servletContext;
        for (SysConfig sysConfig : sysConfigs) {
            servletContext.setAttribute("web_" + sysConfig.getNid(), sysConfig.getValue());
            ContextConfig.putConfig(sysConfig.getNid(), sysConfig.getValue());
        }
    }
}
